package Arraylist.Practice;


import java.util.ArrayList;

/*
题目：自定义4个学生对象，添加到集合中，并遍历

思路：
1、首先要有Student类，
2、创建集合，用来存储学生对象。泛型：<Student>
3、根据类，创建4个学生对象
4、将4个学生对象add到集合中
5、遍历集合

*/
public class Demo02ArrayListStudent {
    public static void main(String[] args) {
        //创建ArrayList集合，以Student类作泛型
        ArrayList<Student> list = new ArrayList<Student>();
        Student one = new Student(21,"洪七公");
        Student two = new Student(22,"洪六");
        Student three = new Student(23,"库李公");
        Student four = new Student(25,"撒比较多公");
        list.add(one);
        list.add(two);
        list.add(three);
        list.add(four);

        for (int i = 0; i <list.size() ; i++) {
            System.out.println("年龄是:"+list.get(i).getAge()+"\t姓名是："+list.get(i).getName());
        }

    }
}




















